package cn.hdu.liang.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class DaytimeClient {
    public static void main(String[] args) {
        try(Socket socket = new Socket("cn.ntp.org.cn", 13)) {

            socket.setSoTimeout(10000);
            InputStream in = socket.getInputStream();
            StringBuilder time = new StringBuilder();
            InputStreamReader reader = new InputStreamReader(in, "ASCII");
            for(int c = reader.read(); c != -1; c = reader.read()) {
                time.append((char) c);
            }
            System.out.println(time);

        } catch(IOException e) {
            System.err.println(e);
        }
    }
}
